package example.bean.learn;

import java.io.Serializable;

public class CalBean implements Serializable{

	/** 
	* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么) 
	*/ 
	private static final long serialVersionUID = -3531181458148396029L;
	
	 private double firstParam;  
	    private double secondParam;  
	    private String operator;  
	    private double result;  
	      
	  
	    public double getFirstParam() {  
	        return firstParam;  
	    }  
	  
	    public void setFirstParam(double firstParam) {  
	        this.firstParam = firstParam;  
	    }  
	  
	    public double getSecondParam() {  
	        return secondParam;  
	    }  
	  
	    public void setSecondParam(double secondParam) {  
	        this.secondParam = secondParam;  
	    }  
	  
	    public String getOperator() {  
	        return operator;  
	    }  
	  
	    public void setOperator(String operator) {  
	        this.operator = operator;  
	    }  
	  
	    public double getResult() {  
	        return result;  
	    }  
	  
	    public void setResult(double result) {  
	        this.result = result;  
	    }  
	  
	    public double calculate() {  
	  
	        result = 0;  
	        try {  
	  
	            if ("+".equals(operator))  
	                result = firstParam + secondParam;  
	  
	            if ("-".equals(operator))  
	                result = firstParam - secondParam;  
	  
	            if ("*".equals(operator))  
	                result = firstParam * secondParam;  
	  
	            if ("/".equals(operator) && (0 != secondParam))  
	  
	                result = firstParam / secondParam;  
	  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	        return result;  
	  
	    }  
	  
	    //判断输入的是不是数字  
	    public boolean isNum(String str) {  
	        return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");  
	    } 

	public CalBean() {
		// TODO Auto-generated constructor stub
	}

}
